package cc.catface.api;

import cn.hutool.cron.CronUtil;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@ServletComponentScan(basePackages = {"cc.catface.api.global.filter"})//过滤器包路径
@Configuration
@SpringBootApplication/*(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})*/
//exclude数据库未连接仍可启动服务
@RestController
@MapperScan(basePackages = {"cc.catface.**.mapper*"})
@ComponentScan(basePackages = {"cc.catface"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        //startTask();
    }

    private static void startTask() {/*静态定时任务*/
        CronUtil.setMatchSecond(true);
        CronUtil.start();
    }

    @Bean/*mybatis分页*/
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @RequestMapping("time")
    public String time() {
        return new Date().toLocaleString() + " from springboot-parent[9001]";
    }
}
